package ink.wbc.easyrule.rule;

import ink.wbc.drools.entity.User;
import org.jeasy.rules.annotation.*;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.support.composite.CompositeRule;
import org.jeasy.rules.support.composite.UnitRuleGroup;

/**
 * @author wbc
 * @date 2021/9/17
 * @desc
 */
public class LotteryCompositeRule extends UnitRuleGroup {

    public LotteryCompositeRule(Object... rules) {
        for (Object rule : rules) {
            addRule(rule);
        }
    }

    @Override
    public int getPriority() {
        return 0;
    }

    @Rule(name = "vipRule", description = "抽奖规则")
    public static class VipRule {
        @Condition
        public boolean isVip(@Fact("user") User user) {
            return user.getVipFlag() == 1;
        }

        @Action
        public void print(@Fact("user") User user) {
            System.out.println("当前玩家为VIP用户");
        }

        @Priority
        public int getPriority() {
            return 1;
        }
    }

    @Rule(name = "MoneyRule", description = "抽奖规则")
    public static class MoneyRule {
        @Condition
        public boolean isAllowLottery(@Fact("user") User user) {
            return user.getMoney() >= 100;
        }

        @Action
        public void print(@Fact("user") User user) {
            System.out.println("当前玩家充值为:" + user.getMoney());
            user.setAllowLotteryFlag(1);
        }

        @Priority
        public int getPriority() {
            return 2;
        }
    }

}
